<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
#add_goods_type_info .box label span {
	display: inline-block;
	width: 74px;
	text-align: right;
}

#add_goods_type_info .box label {
	margin-left: 20px;
}

#add_goods_type_info .formBox {
	padding: 0;
	position: relative;
}

#add_goods_type_info .formBox>div {
	padding: 20px;
}

#add_goods_type_info .updateBox label span {
	width: 96px;
}
</style>
<div class="modal fade" id="add_goods_type_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 360px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增物品分类</h4>
			</div>
			<form id="add_goods_type_form" class="form">
				<input type="hidden" name="firstid" id="firstid">
				<div class="box modal-body">
					<p>
							<label>类别编码</label>
							<input type="text" class="form-control" id="categorycode" readonly placeholder="自动生成">
					</p>
					<p>
							<label class="must">类别名称</label>
							<input type="text" class="form-control" name="categoryname"></input>
					</p>
					<p>
							<label>类别备注</label>
							<input type="text" class="form-control" name="description"></input>
					</p>
				</div>
			</form>
			<div class="red" id="add_goods_type_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn1" onclick="saveAddGoodsType();">保存</button>
				<button type="button" class="btn btn2" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function addGoodsType(id){
	$('#add_goods_type_info :text').val("");
	$("#add_goods_type_info :hidden").val("");
	$("#add_goods_type_info #firstid").val(id);
	$('#add_goods_type_info').modal('show');
}

function saveAddGoodsType(){
	if(!validateAddForm()) return ;
	$.ajax({
		url:"<%=basePath %>category/add.do",
		type:"post",
		async : false,
		dataType:"json",
		data : $("#add_goods_type_form").serialize(),
		success:function(data){
			if(data.result=="success"){
				$("#add_goods_type_msg").html("");
				$('#add_goods_type_info :text').val("");
				$("#add_goods_type_info select").val("");
				$("#add_goods_type_info #firstid").val("");
				$('#add_goods_type_info').modal('hide');
				location.href=location.href;
			}else{
				Prompt.alert("提示：","新增物品分类失败："+data.error);
			}
		},
		error :function(){
			Prompt.alert("提示：","新增物品分类失败！");
		}
	});
}

function validateAddForm(){
 	if(!validateString("类别名称","#add_goods_type_info [name='categoryname']",30,false)){
		return false;
	}
	if(!validateString("类别备注","#add_goods_type_info [name='description']",120,true)){
		return false;
	}
	return true;
}
</script>